package 题目集.hash.字符串哈希;

import java.util.Arrays;
import java.util.Scanner;
//todo:未完成
public class 字符串序号 {
    static int N = 10;
    static int[] fact = new int[N];
    static boolean[] st = new boolean[N];
    static char[] a = new char[N];

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length();
        for (int i = 0; i < n; i++) a[i] = s.charAt(i);
        Arrays.sort(a, 0, n);

        fact[0] = 1;
        for (int i = 1; i < N; i++) fact[i] = fact[i - 1] * i;

        int res = 0;
        for (int i = 0; i < n; i++) {
            int x = s.charAt(i) - 'a';
            for (int j = 0; j < x; j++)
                if (!st[j]) res += fact[n - i - 1];
            st[x] = true;
        }

        System.out.println(res);
    }
}

